package com.yuanlrc.base.dao.common;

import com.yuanlrc.base.entity.common.Goods;
import com.yuanlrc.base.entity.common.HomeUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 物品数据库操作Dao
 */
@Repository
public interface GoodsDao extends JpaRepository<Goods,Long> {
    @Query("select g from Goods g where g.id=:id")
    Goods find(@Param("id") Long id);

    /**
     * 根据用户查询
     * @param homeUser
     * @return
     */
    List<Goods> findByHomeUser(HomeUser homeUser);

    /**
     * 根据用户id和商品id查询
     * @param id
     * @param
     * @return
     */
    @Query("select g from Goods g where g.id=:id and g.homeUser.id=:homeuserId")
    Goods finds(@Param("id") Long id,@Param("homeuserId") Long homeuserId);
}
